package sziit.znk.utils;

import org.dom4j.Element;
import sziit.znk.utils.Enum.Type;

import java.lang.reflect.Field;

public class JavaLangTypeChose {

    @SuppressWarnings("all")
    public static Object javaType(Field field, Object value, Element property) {
        String[] s = field.getType().toString().split(" ");
        if (s[0].equals("class") && !(s[1].equals(Type.LANG_STRING.getJavaType()))){
            return field.getType().toString();
        }
        switch (field.getType().getName()) {
            case "java.lang.Long":
                value = Long.parseLong(property.attributeValue("value"));
                break;
            case "long":
                value = Long.parseLong(property.attributeValue("value"));
                break;
            case "java.lang.Float":
                value = Float.parseFloat(property.attributeValue("value"));
                break;
            case "float":
                value = Float.parseFloat(property.attributeValue("value"));
                break;
            case "java.lang.Integer":
                value = Integer.parseInt(property.attributeValue("value"));
                break;
            case "int":
                value = Integer.parseInt(property.attributeValue("value"));
                break;
            case "java.lang.Double":
                value = Double.parseDouble(property.attributeValue("value"));
                break;
            case "double":
                value = Double.parseDouble(property.attributeValue("value"));
                break;
            case "java.lang.Byte":
                value = Byte.parseByte(property.attributeValue("value"));
                break;
            case "byte":
                value = Byte.parseByte(property.attributeValue("value"));
                break;
            case "java.lang.Boolean":
                value = Boolean.parseBoolean(property.attributeValue("value"));
                break;
            case "boolean":
                value = Boolean.parseBoolean(property.attributeValue("value"));
                break;
            case "java.lang.Short":
                value = Short.parseShort(property.attributeValue("value"));
                break;
            case "short":
                value = Short.parseShort(property.attributeValue("value"));
                break;
        }
        return value;
    }

}
